from lib.config.base import BaseConfig
from utils import common


class SensorConfig(BaseConfig):
    def __init__(self, path):
        super().__init__(path)
        self.__sensors = self.get_enable_sensors() or []

    def is_debug(self):
        debug = common.get_data_value(self.__config, "debug")
        return debug == 1

    def get_enable_sensors(self):
        return common.get_data_value(self.__config, "enable")

    def get_sensor(self, name):
        # print(self.__sensors)
        find_sensor = None
        try:
            for sensor in self.__sensors:
                if sensor["name"] == name:
                    find_sensor = sensor
                    break
            if not find_sensor:
                raise Exception(f"no enable sensor ${name} found")
            return find_sensor
        except Exception as e:
            print(f"read sensor <{name}> failed")
        return None
